package models

import "time"

type Product struct {
	ID          uint           `gorm:"primaryKey" json:"id"`
	Title       string         `gorm:"size:255;not null" json:"title"`
	Type        string         `gorm:"size:100;not null" json:"type"`
	Description string         `gorm:"type:text" json:"description"`
	Price       float64        `gorm:"not null" json:"price"`
	CoverImage  string         `gorm:"size:255" json:"cover_image"`
	CoverAssetID *uint          `json:"cover_asset_id"`
	CoverAsset   *MediaAsset    `gorm:"foreignKey:CoverAssetID" json:"cover_asset,omitempty"`
	FreePreviewLimit int        `gorm:"not null;default:0" json:"free_preview_limit"`
	IsPublished bool           `gorm:"not null;default:true" json:"is_published"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	Images      []ProductImage `gorm:"foreignKey:ProductID" json:"images"`
}

type ProductImage struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	ProductID uint      `gorm:"index;not null" json:"product_id"`
	URL       string    `gorm:"size:255;not null" json:"url"`
	SortOrder int       `gorm:"default:0" json:"sort_order"`
	IsPreview bool      `gorm:"not null;default:false" json:"is_preview"`
	AssetID   *uint     `json:"asset_id"`
	Asset     *MediaAsset `gorm:"foreignKey:AssetID" json:"asset,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

func (Product) TableName() string {
	return "products"
}

func (ProductImage) TableName() string {
	return "product_images"
}
